/**
 * @author zhounan 
 * @date 2024年7月15日
 * @version V1.0
 */
package org.zn.etl.config;

import java.util.List;
import java.util.Map;

import javax.sql.DataSource;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;

/**
 * @author zhounan 
 * @date 2024年7月15日
 * @version V1.0
 */
//@Configuration
//@MapperScan(basePackages = "org.zn.etl.extbiz.dao", sqlSessionFactoryRef = "regSqlSessionFactory")
public class RegMybatisPlusConfig {
	
	@Bean(name = "regSqlSessionFactory")
	//@Qualifier("shardingSphereDataSource")  ShardingSphereDataSource
     SqlSessionFactory db1SqlSessionFactory(Map<String, DataSource>  datasource)
            throws Exception {
	
		DataSource  shardingSphereDataSource=datasource.get("shardingSphereDataSource");
		
        MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean();

        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();

        //分页插件
        //mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.POSTGRE_SQL));
        bean.setDataSource(shardingSphereDataSource);
        // 设置mybatis的xml所在位置
        bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:mapper/extbiz/*.xml"));
        bean.setPlugins(mybatisPlusInterceptor);
        return bean.getObject();
    }

    @Bean("regSqlSessionTemplate")
     SqlSessionTemplate db1SqlSessionTemplate(
            @Qualifier("regSqlSessionFactory") SqlSessionFactory sessionFactory) {
        return new SqlSessionTemplate(sessionFactory);
    }


}
